﻿// Copyright 2010 Maxime Serrano <lastchronicler@gmail.com>
// Copyright 2009, 2010 Matvei Stefarov <me@matvei.org>
using System;
using System.Text;
using System.Net;

namespace ForgeCraft
{
    public sealed class WarpInfo
    {
        public const int fieldCount = 6;

        public string location;
        public string world;
        public DateTime createdDate;
        public byte minPermission;
        public string ownerName;
        public bool isPublic;
        public string warpName;

        // === Serialization & Defaults =======================================
        // fabricate info for a player
        public WarpInfo(BlockPosition bp)
        {
            string loc = bp.x + ":" + bp.y + ":" + bp.z;
            
            location = loc;
            world = Config.GetString(ConfigKey.World);
            createdDate = DateTime.UtcNow;
            minPermission = 0;
            ownerName = "-";
            isPublic = true;
            warpName = "-";
        }

        // load info from file
        public WarpInfo(string[] fields)
        {
            location = fields[0];
            world = fields[1];
            createdDate = DateTime.Parse(fields[2]);
            minPermission = byte.Parse(fields[3]);
            ownerName = fields[4];
            isPublic = bool.Parse(fields[5]);
            warpName = fields[6];
        }


        // save to file
        public string Serialize()
        {
            string[] fields = new string[fieldCount];

            fields[0] = location;
            fields[1] = world;
            fields[2] = createdDate.ToString();
            fields[3] = minPermission.ToString();
            fields[4] = ownerName;
            fields[5] = isPublic.ToString();
            fields[6] = warpName;

            return String.Join(",", fields);
        }
    }
}